/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PublicidadGUI.java
 *
 * Created on Jan 6, 2012, 10:41:35 PM
 */
package Gui;

import Logica.CreacionInformacion;
import Logica.EdicionInformacion;
import Logica.EliminacionInformacion;
import Oracle.OracleMethods;
import java.awt.Component;
import java.awt.event.MouseEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import java.sql.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author odmaestrams
 */
public class PublicidadGUI extends javax.swing.JFrame {

    private SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy");
    private SimpleDateFormat fecha2 = new SimpleDateFormat("yyyy-MM-dd");
    
    private Integer porcentajeDescuentoTotal;
    private String[] infoAlquiler = null;
    private String rifClienteAnterior;
    private Integer nroKioscoAnterior, formaPagoAnt, servicioAnt;
    
    /** Creates new form PublicidadGUI */
    public PublicidadGUI() throws SQLException {
        initComponents();
        this.setLocationRelativeTo(null);
        this.jTabbedPane1.setEnabledAt(1, false);
        this.jTabbedPane1.setTitleAt(1, "");
        this.posicionLabel.setVisible(false);
        infoBox.addItem("RIF - Cliente");
        infoBox.setSelectedItem("RIF - Cliente");     
        ArrayList<String> clientsArray = OracleMethods.todosLosClientes();
        for (int i = 0; i < clientsArray.size(); i++)
            infoBox.addItem(clientsArray.get(i));
        }
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    
    public final void mostrarInfoAlquiler(String rifCliente) throws SQLException {
        this.infoPubli_Table.removeAll();
        
        DefaultTableModel dm = new DefaultTableModel();
        dm.addColumn("Nro.Alquiler");
        dm.addColumn("Kiosco");
        dm.addColumn("Posicion");
        dm.addColumn("Fecha Inicio");
        dm.addColumn("Fecha Fin");
        
        Connection con = OracleMethods.oracleConnection();
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT alquiler_PK, kiosco_PK_FK, posicion, fechaInicio, fechaFin"
                + " FROM ao_alquiler WHERE ao_alquiler.rif_PK_FK = " + "'" + rifCliente + "'");
            
        while(rs.next()) { 
            Vector row = new Vector();
            row.add(rs.getInt("alquiler_PK"));
            row.add(rs.getInt("kiosco_PK_FK"));
            row.add(rs.getString("posicion"));
            row.add(fecha.format(rs.getDate("fechaInicio")));
            row.add(fecha.format(rs.getDate("fechaFin")));
            dm.addRow(row);
        }
        
        
        this.infoPubli_Table.setModel(dm);
        //this.infoPubli_Table.setDefaultRenderer(String.class, new TableRender());
        this.infoPubli_Table.setVisible(true);
   
        stmt.close();
        rs.close();
        con.close();
        
       
        
        
        
        
        //String stringTemp = fecha.format(new Date());
        //Prueba para pintar una fila de la tabla si la fecha de fin ya paso.
        /*try {
            Date now = fecha.parse(stringTemp);
            Date fechaTabla = null;
            for (int i = 0; i < infoPubli_Table.getRowCount(); i++){
                fechaTabla = fecha.parse(infoPubli_Table.getValueAt(i, 4).toString());
                if (fechaTabla.before(now)){
                    this.infoPubli_Table.getCellRenderer(i, 4).getTableCellRendererComponent(infoPubli_Table, infoPubli_Table.getValueAt(i, 4), true, true, i, 4).setForeground(Color.red);
                    
                }
            }
        } catch (ParseException ex) {
            System.out.println(ex);
        }*/
        
        
        
       
        
    }
    
    public void limpiarCamposCreacionAlquiler() {
        this.clientesBox.setSelectedItem("RIF - Cliente");
        this.kioscosBox.setSelectedItem("Kiosco - Nombre");
        this.posicionBox.setSelectedItem("Selecione una posicion");
        this.serviciosBox.setSelectedItem("Seleccione un servicio");
        this.formaPagoBox.setSelectedItem("Seleccione una forma de pago");
        this.fechaInicioC.setDate(null);
        this.fechaFinC.setDate(null);
        montoField.setText("");
    }
    
    public void eliminarInfoCreacionAlquiler() {
        this.clientesBox.removeAllItems();
        this.kioscosBox.removeAllItems();
        this.posicionBox.removeAllItems();
        this.serviciosBox.removeAllItems();
        this.formaPagoBox.removeAllItems();
        this.fechaInicioC.setDate(null);
        this.fechaFinC.setDate(null);
        montoField.setText("");
    }
    
    public void limpiarCamposInfoAlquiler() {
        this.registrarButton.setEnabled(true);
        this.editarButton.setText("Editar");
        this.registrarButton.setText("Registrar");
    }
    
    public void calcularCostoAlquiler() {
        String[] infoCostoAlquiler = null;
        
        if (kioscosBox.getSelectedItem() != null)
        if (!kioscosBox.getSelectedItem().equals("Kiosco - Nombre")){
            try {
                String posicion = posicionBox.getSelectedItem().toString();
                String formaPago_PK = formaPagoBox.getSelectedItem().toString().substring(0,1);
                String servicio_PK = serviciosBox.getSelectedItem().toString().substring(0,1);
                Integer nroKiosco = Integer.parseInt(kioscosBox.getSelectedItem().toString().substring(0, kioscosBox.getSelectedItem().toString().indexOf(" ")));
            
                infoCostoAlquiler = OracleMethods.buscarCostoAlquiler(nroKiosco,posicion,formaPago_PK,servicio_PK).split(";");
           
                if (infoCostoAlquiler != null){
                    int costoPosicion = Integer.parseInt(infoCostoAlquiler[0]);
                    int descuentoTipoPago = Integer.parseInt(infoCostoAlquiler[1].substring(0,infoCostoAlquiler[1].indexOf("%")));
                    int descuentoServicio = Integer.parseInt(infoCostoAlquiler[2].substring(0,infoCostoAlquiler[2].indexOf("%")));
                
                    costoPosicion = (costoPosicion - (costoPosicion * (descuentoTipoPago + descuentoServicio)/100));
                    this.montoField.setText(String.valueOf(costoPosicion));
                
                    porcentajeDescuentoTotal = (descuentoTipoPago + descuentoServicio);
                }
            
            } catch (SQLException ex) {
            System.out.println(ex);
            }
        }
    }
    
    public void calcularFechasAlquiler(String tipoServicio) {
        if (!(tipoServicio.equals("S")) && (this.fechaInicioC.getDate() != null)){
            Calendar now = this.fechaInicioC.getCalendar();
       
            if (tipoServicio.equals("1")){
                now.add(Calendar.YEAR, 1);
            }
            else if (tipoServicio.equals("2")){
                now.add(Calendar.MONTH, 6);
            }
            else if (tipoServicio.equals("3")){
                now.add(Calendar.MONTH, 3);
            }
            else if (tipoServicio.equals("4")){
                now.add(Calendar.MONTH, 1);
            }
            else if (tipoServicio.equals("5")){
                now.add(Calendar.DATE, 15);
            }
        
            this.fechaFinC.setDate(now.getTime());
        }
    }
    
    public void infoCreacionAlquiler(){
        try {            
            ArrayList<String> infoArray = new ArrayList<String>();
            
            if((kioscosBox.getSelectedItem() == null) && (posicionBox.getSelectedItem() == null) 
                    && (serviciosBox.getSelectedItem() == null) && (formaPagoBox.getSelectedItem() == null)){
                
                //Mostrar todos los clientes en el ComboBox correspondiente.
                for (int i = 0; i < infoBox.getItemCount(); i++){
                    clientesBox.addItem(infoBox.getItemAt(i));
                }
                clientesBox.setSelectedItem(infoBox.getSelectedItem());
            
                //Mostrar todos los kioscos en el ComboBox correspondiente.
                infoArray = OracleMethods.todosLosKioscos();
                kioscosBox.addItem("Kiosco - Nombre");
                for (int i = 0; i < infoArray.size(); i++)
                    kioscosBox.addItem(infoArray.get(i));
            
                //Mostrar todos las posiciones en el ComboBox correspondiente.
                posicionBox.addItem("Seleccione una posicion");
                posicionBox.addItem("Izquierda");
                posicionBox.addItem("Derecha");
                posicionBox.addItem("Detras");
            
                //Mostrar todos los tipos de servicios en el ComboBox correspondiente.
                infoArray = OracleMethods.todosLosServicios();
                serviciosBox.addItem("Seleccione un servicio");
                serviciosBox.setSelectedItem("Seleccione un servicio");
                for (int i = 0; i < infoArray.size(); i++){
                    serviciosBox.addItem(infoArray.get(i));
                }
                
                infoArray = OracleMethods.todosLosTiposPago();
                formaPagoBox.addItem("Seleccione una forma de pago");
                formaPagoBox.setSelectedItem("Seleccione una forma de pago");
                for (int i = 0; i < infoArray.size(); i++){
                    formaPagoBox.addItem(infoArray.get(i));
                }
            }
            
        } catch (SQLException ex) {
            System.out.println(ex);
        }
    }
    
    public void validarPosicionesDisponibles() {
        try {
            String posicion = null;
            int repeticion = 0;
            posicionBox.removeAllItems();
            posicionBox.addItem("Seleccione una posicion");
            posicionBox.addItem("Izquierda");
            posicionBox.addItem("Derecha");
            posicionBox.addItem("Detras");
            
            if(this.infoPubli_Table.getSelectedRow() != -1){
                int row = this.infoPubli_Table.getSelectedRow();
                posicion =  this.infoPubli_Table.getModel().getValueAt(row, 2).toString();
            }
           
            if (!kioscosBox.getSelectedItem().toString().equals("Kiosco - Nombre")){                
                Integer nroKiosco = Integer.parseInt(kioscosBox.getSelectedItem().toString().substring(0, kioscosBox.getSelectedItem().toString().indexOf(" ")));
                String[] posicionesOcupadas = OracleMethods.buscarPosicionesOcupadas(nroKiosco).split(";");
  
                for (int i = 1; i < posicionBox.getItemCount(); i++){
                        for (int j = 0; j < posicionesOcupadas.length; ++j){
                            try {
                                if ((posicionBox.getItemAt(i).toString().equals(posicionesOcupadas[j].toString())) && (fecha2.parse(posicionesOcupadas[j+1]).after(new Date()))){
                                    posicionBox.removeItemAt(i);
                                    i--;
                                }
                        
                            } catch (ParseException ex) {
                                System.out.println(ex);
                            }
                            j = j + 1;
                            
                        }
                        
                        if (posicionBox.getItemAt(i).toString().equals(posicion))
                            repeticion ++;
                }
                
                if ((repeticion == 0) && (posicion != null))
                    this.posicionBox.addItem(posicion);
            }
            } catch (SQLException ex) {
                System.out.println(ex);
            }
    }
    
    public void mostrarInfoEdicion(String nroFormaPago, String nroServicio, String montoAlquiler, 
            String posicion, String fechaInicio, String fechaFin, String rifCliente, String nroKiosco) {
        
        try {
            for (int i = 0; i < kioscosBox.getItemCount(); i++){
                if (kioscosBox.getItemAt(i).toString().substring(0, kioscosBox.getItemAt(i).toString().indexOf(" ")).equals(nroKiosco)){
                    kioscosBox.setSelectedItem(kioscosBox.getItemAt(i));
                    break;
                }
            }
            
            for (int i = 0; i < clientesBox.getItemCount(); i++){
                if (clientesBox.getItemAt(i).toString().substring(0, clientesBox.getItemAt(i).toString().indexOf(" ")).equals(rifCliente)){
                    clientesBox.setSelectedItem(clientesBox.getItemAt(i));
                    break;
                }
            }
            
            for (int i = 0; i < serviciosBox.getItemCount(); i++){
                if (serviciosBox.getItemAt(i).toString().substring(0, serviciosBox.getItemAt(i).toString().indexOf(" ")).equals(nroServicio)){
                    serviciosBox.setSelectedItem(serviciosBox.getItemAt(i));
                    break;
                }
            }
            
            for (int i = 0; i < formaPagoBox.getItemCount(); i++){
                if (formaPagoBox.getItemAt(i).toString().substring(0, formaPagoBox.getItemAt(i).toString().indexOf(" ")).equals(nroFormaPago)){
                    formaPagoBox.setSelectedItem(formaPagoBox.getItemAt(i));
                    break;
                }
            }
            
            this.posicionBox.setSelectedItem(posicion);
            this.serviciosBox.setSelectedItem(nroServicio);
            this.fechaInicioC.setDate(fecha.parse(fechaInicio));
            this.fechaFinC.setDate(fecha.parse(fechaFin));
            this.montoField.setText(montoAlquiler);
            
        } catch (ParseException ex) {
            System.out.println(ex);
        }
        
        
        
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        infoAlq_Panel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        infoPubli_Table = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        infoPubli_Text = new javax.swing.JTextArea();
        creacionAlq_Panel = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        clientesBox = new javax.swing.JComboBox();
        kioscosBox = new javax.swing.JComboBox();
        posicionBox = new javax.swing.JComboBox();
        serviciosBox = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        montoField = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        posicionLabel = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        formaPagoBox = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        fechaInicioC = new com.toedter.calendar.JDateChooser();
        jLabel8 = new javax.swing.JLabel();
        fechaFinC = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        infoBox = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        backButton = new javax.swing.JButton();
        registrarButton = new javax.swing.JButton();
        editarButton = new javax.swing.JButton();
        eliminarButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBounds(new java.awt.Rectangle(0, 22, 800, 550));
        setMinimumSize(new java.awt.Dimension(800, 600));
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Manejo de publicidad"));

        jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTabbedPane1MouseReleased(evt);
            }
        });
        jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged(evt);
            }
        });

        infoAlq_Panel.setLayout(null);

        infoPubli_Table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nro.Alquiler", "Kiosco", "Posicion", "Fecha Inicio", "Fecha Fin"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        infoPubli_Table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                infoPubli_TableMouseReleased(evt);
            }
        });
        infoPubli_Table.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                infoPubli_TableFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                infoPubli_TableFocusLost(evt);
            }
        });
        jScrollPane1.setViewportView(infoPubli_Table);

        infoAlq_Panel.add(jScrollPane1);
        jScrollPane1.setBounds(0, 0, 440, 350);

        infoPubli_Text.setBackground(new java.awt.Color(153, 255, 255));
        infoPubli_Text.setColumns(20);
        infoPubli_Text.setEditable(false);
        infoPubli_Text.setRows(5);
        jScrollPane2.setViewportView(infoPubli_Text);

        infoAlq_Panel.add(jScrollPane2);
        jScrollPane2.setBounds(440, 0, 270, 350);

        jTabbedPane1.addTab("Informacion alquiler", infoAlq_Panel);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Info. Alquiler"));

        jLabel2.setText("Cliente:");

        jLabel3.setText("Kiosco:");

        jLabel4.setText("Posicion:");

        jLabel5.setText("Servicio:");

        kioscosBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kioscosBoxActionPerformed(evt);
            }
        });

        posicionBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                posicionBoxActionPerformed(evt);
            }
        });

        serviciosBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                serviciosBoxActionPerformed(evt);
            }
        });

        jLabel10.setText("Monto:");

        montoField.setEditable(false);
        montoField.setMaximumSize(new java.awt.Dimension(20, 28));

        jLabel11.setFont(new java.awt.Font("Lucida Grande", 0, 10));
        jLabel11.setText("Bs.");

        posicionLabel.setFont(new java.awt.Font("Lucida Grande", 0, 10));
        posicionLabel.setText("Lo siento, no existen posiciones disponibles para este kiosco");

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel4Layout.createSequentialGroup()
                                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel4)
                                    .add(jLabel3)
                                    .add(jLabel2))
                                .add(18, 18, 18)
                                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(posicionBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(clientesBox, 0, 260, Short.MAX_VALUE)
                                    .add(kioscosBox, 0, 260, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                                        .add(jLabel10)
                                        .add(18, 18, 18)
                                        .add(montoField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jLabel11))))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, posicionLabel))
                        .addContainerGap())
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jLabel5)
                        .add(18, 18, 18)
                        .add(serviciosBox, 0, 194, Short.MAX_VALUE)
                        .add(87, 87, 87))))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(clientesBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(kioscosBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(posicionBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(posicionLabel)
                .add(18, 18, 18)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(serviciosBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 49, Short.MAX_VALUE)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(jLabel10)
                    .add(montoField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Forma de pago"));

        jLabel9.setText("Forma de pago:");

        formaPagoBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formaPagoBoxActionPerformed(evt);
            }
        });

        jLabel7.setText("Fecha inicio:");

        fechaInicioC.setDateFormatString("dd/MM/yyyy");
        fechaInicioC.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                fechaInicioCPropertyChange(evt);
            }
        });

        jLabel8.setText("Fecha Fin:");

        fechaFinC.setDateFormatString("dd/MM/yyyy");
        fechaFinC.setEnabled(false);

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(jLabel9)
                        .add(18, 18, 18)
                        .add(formaPagoBox, 0, 125, Short.MAX_VALUE))
                    .add(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel7)
                            .add(jPanel5Layout.createSequentialGroup()
                                .add(4, 4, 4)
                                .add(jLabel8)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(fechaFinC, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(fechaInicioC, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(jLabel9))
                    .add(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(formaPagoBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(18, 18, 18)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(fechaInicioC, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(13, 13, 13)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(fechaFinC, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout creacionAlq_PanelLayout = new org.jdesktop.layout.GroupLayout(creacionAlq_Panel);
        creacionAlq_Panel.setLayout(creacionAlq_PanelLayout);
        creacionAlq_PanelLayout.setHorizontalGroup(
            creacionAlq_PanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(creacionAlq_PanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(14, 14, 14)
                .add(jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        creacionAlq_PanelLayout.setVerticalGroup(
            creacionAlq_PanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(creacionAlq_PanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(creacionAlq_PanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Creacion alquiler", creacionAlq_Panel);

        jLabel1.setText("Cliente:");

        infoBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                infoBoxActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Lucida Grande", 0, 10));
        jLabel6.setText("Porfavor seleccione una opcion de la lista.");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 744, Short.MAX_VALUE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(29, 29, 29)
                        .add(jLabel1)
                        .add(14, 14, 14)
                        .add(infoBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 228, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jLabel6)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel6)
                    .add(infoBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 3, Short.MAX_VALUE)
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 406, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        backButton.setText("Atras");
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });

        registrarButton.setText("Registrar");
        registrarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                registrarButtonActionPerformed(evt);
            }
        });

        editarButton.setText("Editar");
        editarButton.setEnabled(false);
        editarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarButtonActionPerformed(evt);
            }
        });

        eliminarButton.setText("Eliminar");
        eliminarButton.setEnabled(false);
        eliminarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eliminarButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(registrarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(editarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(eliminarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 450, Short.MAX_VALUE)
                        .add(backButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(backButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(registrarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(editarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(eliminarButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
    eliminarInfoCreacionAlquiler();
    this.dispose();
}//GEN-LAST:event_backButtonActionPerformed

private void infoPubli_TableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_infoPubli_TableMouseReleased
    this.infoPubli_Text.setText("");
    int row = this.infoPubli_Table.getSelectedRow();
    
    Integer nroAlquiler =  Integer.parseInt(this.infoPubli_Table.getModel().getValueAt(row, 0).toString());
    Integer nroKiosco = Integer.parseInt(this.infoPubli_Table.getModel().getValueAt(row, 1).toString());
    String posicion = (String) this.infoPubli_Table.getModel().getValueAt(row, 2).toString();
    String fechaInicio = (String) this.infoPubli_Table.getModel().getValueAt(row, 3).toString();
    String fechaFin = (String) this.infoPubli_Table.getModel().getValueAt(row, 4).toString();
 
    System.out.println(nroAlquiler);
    System.out.println(nroKiosco);
    try {
        infoAlquiler = OracleMethods.buscarInfoAlquiler(nroAlquiler, nroKiosco).split(";");      
        } catch (SQLException ex) {
            System.out.println(ex);
        }

    if (infoAlquiler != null){
        infoPubli_Text.setText("*Informacion del alquiler:\n     " +
            "\n     Numero de alquiler:\n       " + nroAlquiler + "\n" +
            "\n     Fecha de Inicio:\n       " + fechaInicio + "\n" +
            "\n     Fecha de Fin:\n       " + fechaFin + "\n" +
            "\n     Kioco a alquilar:\n       " + nroKiosco + " - " + infoAlquiler[4] + "\n" +
            "\n     Posicion:\n       " + posicion + "\n" +
            "\n     Costo del alquiler:\n       " + infoAlquiler[5] + "\n" +
            "\n*Informacion del pago:\n       " + 
            "\n     Tipo de pago:\n       " + infoAlquiler[0] + "\n" +
            "\n     Porcentaje de descuento:\n       " + infoAlquiler[1] + "\n" +
            "\n*Informacion del servicio:\n       " +
            "\n     Tipo de alquiler: " + infoAlquiler[2] + "\n" + 
            "\n     Porcentaje de descuento: " + infoAlquiler[3]);
    }
}//GEN-LAST:event_infoPubli_TableMouseReleased

private void infoBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_infoBoxActionPerformed
        try {   
            mostrarInfoAlquiler(infoBox.getSelectedItem().toString().substring(0, infoBox.getSelectedItem().toString().indexOf(" ")));
            if (infoBox.getSelectedItem().equals("RIF - Cliente")){
                this.limpiarCamposInfoAlquiler();
                this.infoPubli_Text.setText("");
                this.editarButton.setEnabled(false);
                this.eliminarButton.setEnabled(false);
            }
        }
        
        catch (SQLException ex) {
            System.out.println(ex);
        }
        
}//GEN-LAST:event_infoBoxActionPerformed

private void eliminarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eliminarButtonActionPerformed
    this.registrarButton.setEnabled(false);
    this.editarButton.setEnabled(false);
    
    int confirmacion = JOptionPane.showConfirmDialog(this, "¿Desea eliminar ésta informacion de alquiler?");

    if(confirmacion == 0){
        int row = this.infoPubli_Table.getSelectedRow();
        
        Integer nroAlquiler =  Integer.parseInt(this.infoPubli_Table.getModel().getValueAt(row, 0).toString());
        Integer nroKiosco = Integer.parseInt(this.infoPubli_Table.getModel().getValueAt(row, 1).toString());
        String posicion = (String) this.infoPubli_Table.getModel().getValueAt(row, 2).toString();
        String fechaInicio = (String) this.infoPubli_Table.getModel().getValueAt(row, 3).toString();
        String fechaFin = (String) this.infoPubli_Table.getModel().getValueAt(row, 4).toString();
        String rifCliente = infoBox.getSelectedItem().toString().substring(0, infoBox.getSelectedItem().toString().indexOf(" "));
        
        try {
            infoAlquiler = OracleMethods.buscarInfoAlquiler(nroAlquiler, null).split(";");
            Integer formaPago = Integer.parseInt(infoAlquiler[0].toString());
            Integer servicio = Integer.parseInt(infoAlquiler[1].toString());
            
            
            int resultado = EliminacionInformacion.eliminarAlquiler(nroAlquiler, fechaInicio, fechaFin, posicion, rifCliente, formaPago, servicio, nroKiosco);
            if (resultado != 0){
                JOptionPane.showMessageDialog(this, "Eliminacion Exitosa");
                this.mostrarInfoAlquiler(infoBox.getSelectedItem().toString().substring(0, infoBox.getSelectedItem().toString().indexOf(" ")));
                this.infoPubli_Text.setText("");
            }
            
        } catch (SQLException ex) {
            System.out.println(ex);
        }   
    }
    
    limpiarCamposInfoAlquiler();
    this.editarButton.setEnabled(true);
    
    
}//GEN-LAST:event_eliminarButtonActionPerformed

private void registrarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_registrarButtonActionPerformed
    if(registrarButton.getText().equals("Registrar")){
        this.jTabbedPane1.setEnabledAt(1, true);
        this.creacionAlq_Panel.setVisible(true);
        this.jTabbedPane1.setSelectedIndex(1);
        this.eliminarButton.setEnabled(false);
        this.editarButton.setEnabled(false);
        this.clientesBox.setSelectedItem(this.infoBox.getSelectedItem());
        this.jTabbedPane1.setTitleAt(1, "Creacion alquiler");
        this.registrarButton.setText("Confirmar");
        infoCreacionAlquiler();
    }
    else {
        if((clientesBox.getSelectedItem().equals("RIF - Cliente")) || (kioscosBox.getSelectedItem().equals("Kiosco - Nombre")) 
            || ((posicionBox.getSelectedItem().equals("Seleccione una posicion"))) || (serviciosBox.getSelectedItem().equals("Seleccione un servicio")) 
            || (formaPagoBox.getSelectedItem().equals("Seleccione un tipo") || (fechaInicioC.getDate() == null)
            || (fechaFinC.getDate() == null))){

            JOptionPane.showMessageDialog(this, "Error, campos incompletos o erroneos");
        }
        else{
            String rifCliente = clientesBox.getSelectedItem().toString().substring(0, clientesBox.getSelectedItem().toString().indexOf(" "));
            String fechaInicio = fecha.format(this.fechaInicioC.getDate());
            String fechaFin = fecha.format(this.fechaFinC.getDate());
            String posicion = posicionBox.getSelectedItem().toString();
            Integer formaPago = Integer.parseInt(formaPagoBox.getSelectedItem().toString().substring(0, formaPagoBox.getSelectedItem().toString().indexOf(" ")));
            Integer servicio = Integer.parseInt(serviciosBox.getSelectedItem().toString().substring(0,serviciosBox.getSelectedItem().toString().indexOf(" ")));
            Integer nroKiosco = Integer.parseInt(kioscosBox.getSelectedItem().toString().substring(0,kioscosBox.getSelectedItem().toString().indexOf(" ")));
            Integer costoAlquiler = Integer.parseInt(montoField.getText());
            
            this.eliminarButton.setEnabled(false);
            this.editarButton.setEnabled(false);
        
            try {
                int resultado = CreacionInformacion.crearAlquiler(fechaInicio, fechaFin, posicion, rifCliente, formaPago, servicio, nroKiosco, costoAlquiler, porcentajeDescuentoTotal);
                if (resultado != 0){
                    JOptionPane.showMessageDialog(this, "Registro Exitoso");
                    limpiarCamposInfoAlquiler();
                    limpiarCamposCreacionAlquiler();
                    this.jTabbedPane1.setSelectedIndex(0);
                    this.mostrarInfoAlquiler(infoBox.getSelectedItem().toString().substring(0, infoBox.getSelectedItem().toString().indexOf(" ")));
                    this.infoPubli_Text.setText("");
                    this.jTabbedPane1.setEnabledAt(1, false);
                    this.jTabbedPane1.setTitleAt(1, "");
                }
            } catch (SQLException ex) {
                System.out.println(ex);
            }   
        }
    }
}//GEN-LAST:event_registrarButtonActionPerformed

private void posicionBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_posicionBoxActionPerformed
    if ((posicionBox.getSelectedItem() != null) && (serviciosBox.getSelectedItem() != null) 
            && (formaPagoBox.getSelectedItem() != null)  && (kioscosBox.getSelectedItem() != null)){
        
        if ((posicionBox.getSelectedItem().equals("Seleccione una posicion")) 
                || (serviciosBox.getSelectedItem().equals("Seleccione un servicio"))
                || (formaPagoBox.getSelectedItem().equals("Seleccione una forma de pago"))
                || (kioscosBox.getSelectedItem().equals("Kiosco - Nombre"))){
          
            montoField.setText("0");
        }
        else
            calcularCostoAlquiler();
    }
}//GEN-LAST:event_posicionBoxActionPerformed

private void serviciosBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_serviciosBoxActionPerformed
    if ((posicionBox.getSelectedItem() != null) && (serviciosBox.getSelectedItem() != null) 
            && (formaPagoBox.getSelectedItem() != null) && (kioscosBox.getSelectedItem() != null)){
        
        calcularFechasAlquiler(serviciosBox.getSelectedItem().toString().substring(0,1));
        
        if ((posicionBox.getSelectedItem().equals("Seleccione una posicion")) 
                || (serviciosBox.getSelectedItem().equals("Seleccione un servicio"))
                || (formaPagoBox.getSelectedItem().equals("Seleccione una forma de pago"))
                || (kioscosBox.getSelectedItem().equals("Kiosco - Nombre"))){
          
            montoField.setText("0");
        }
        else
            calcularCostoAlquiler();
    }
}//GEN-LAST:event_serviciosBoxActionPerformed

private void formaPagoBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formaPagoBoxActionPerformed
    if ((posicionBox.getSelectedItem() != null) && (serviciosBox.getSelectedItem() != null) 
            && (formaPagoBox.getSelectedItem() != null)  && (kioscosBox.getSelectedItem() != null)){
        
        if ((posicionBox.getSelectedItem().equals("Seleccione una posicion")) 
                || (serviciosBox.getSelectedItem().equals("Seleccione un servicio"))
                || (formaPagoBox.getSelectedItem().equals("Seleccione una forma de pago"))
                || (kioscosBox.getSelectedItem().equals("Kiosco - Nombre"))){
          
            montoField.setText("0");
        }
        else
            calcularCostoAlquiler();
    }
}//GEN-LAST:event_formaPagoBoxActionPerformed

private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
    if (this.creacionAlq_Panel.isShowing()){
        infoBox.setEnabled(false);
        //infoCreacionAlquiler();
        if (this.registrarButton.getText().equals("Editar")){
            this.registrarButton.setText("Confirmar");
            this.registrarButton.setEnabled(false);
            this.eliminarButton.setEnabled(false);
        }
    }
    else{
        infoBox.setEnabled(true);
        this.registrarButton.setText("Registrar");
        this.limpiarCamposCreacionAlquiler();
        this.registrarButton.setEnabled(true);
        this.editarButton.setEnabled(false);
        this.eliminarButton.setEnabled(false);
        
        if (this.infoPubli_Table.getRowSelectionAllowed()){
            this.editarButton.setEnabled(false);
            this.eliminarButton.setEnabled(false);
        }
        
    }
}//GEN-LAST:event_jTabbedPane1StateChanged

private void kioscosBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kioscosBoxActionPerformed
    if ((posicionBox.getSelectedItem() != null) && (serviciosBox.getSelectedItem() != null) 
            && (formaPagoBox.getSelectedItem() != null)  && (kioscosBox.getSelectedItem() != null)){
        
        //if (!this.editarButton.isEnabled())
            validarPosicionesDisponibles();
        
        if ((posicionBox.getSelectedItem().equals("Seleccione una posicion")) 
                || (serviciosBox.getSelectedItem().equals("Seleccione un servicio"))
                || (formaPagoBox.getSelectedItem().equals("Seleccione una forma de pago"))
                || (kioscosBox.getSelectedItem().equals("Kiosco - Nombre"))){
          
            montoField.setText("0");
            
            if((posicionBox.getItemCount() == 1))
                this.posicionLabel.setVisible(true);
            else
                this.posicionLabel.setVisible(false);
        }
        else{
            calcularCostoAlquiler();
        }
    }
}//GEN-LAST:event_kioscosBoxActionPerformed

private void infoPubli_TableFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_infoPubli_TableFocusGained
    this.infoPubli_Table.setRowSelectionAllowed(true);
    if(this.infoPubli_Table.getSelectedRow() != -1){
        this.editarButton.setEnabled(true);
        this.eliminarButton.setEnabled(true);
    }
}//GEN-LAST:event_infoPubli_TableFocusGained

private void infoPubli_TableFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_infoPubli_TableFocusLost
    
    if (!this.editarButton.requestFocus(true))
        this.editarButton.setEnabled(false);
    
    if (!this.eliminarButton.requestFocus(true))
        this.eliminarButton.setEnabled(false);
}//GEN-LAST:event_infoPubli_TableFocusLost

private void jTabbedPane1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane1MouseReleased
    if (this.jTabbedPane1.getSelectedIndex() == 0){
        this.jTabbedPane1.setTitleAt(1, "");
        this.jTabbedPane1.setEnabledAt(1, false);
        
        limpiarCamposInfoAlquiler();
        
        if (this.infoPubli_Table.getSelectedRow() != -1){
            this.eliminarButton.setEnabled(true);
            this.editarButton.setEnabled(true);
        }
        
    }
}//GEN-LAST:event_jTabbedPane1MouseReleased

private void editarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarButtonActionPerformed
    int row = this.infoPubli_Table.getSelectedRow();
    
    Integer nroAlquiler =  Integer.parseInt(this.infoPubli_Table.getModel().getValueAt(row, 0).toString());
    
    if (editarButton.getText().equals("Editar")){
        this.jTabbedPane1.setEnabledAt(1, true);
        this.creacionAlq_Panel.setVisible(true);
        this.jTabbedPane1.setSelectedIndex(1);
        this.eliminarButton.setEnabled(false);
        this.registrarButton.setEnabled(false);
        this.jTabbedPane1.setTitleAt(1, "Edicion de alquiler");
        this.editarButton.setText("Confirmar");
        
        Integer nroKiosco = Integer.parseInt(this.infoPubli_Table.getModel().getValueAt(row, 1).toString());
        String posicion = (String) this.infoPubli_Table.getModel().getValueAt(row, 2).toString();
        String fechaInicio = (String) this.infoPubli_Table.getModel().getValueAt(row, 3).toString();
        String fechaFin = (String) this.infoPubli_Table.getModel().getValueAt(row, 4).toString();
        String rifCliente = infoBox.getSelectedItem().toString().substring(0, infoBox.getSelectedItem().toString().indexOf(" "));
        
        
        try {
            infoAlquiler = OracleMethods.buscarInfoAlquiler(nroAlquiler, null).split(";");
        } catch (SQLException ex) {
            System.out.println(ex);
        }
            
        if(infoAlquiler != null){
            mostrarInfoEdicion(infoAlquiler[0], infoAlquiler[1], infoAlquiler[2], posicion, fechaInicio, fechaFin, rifCliente, nroKiosco.toString());
            calcularCostoAlquiler();
            rifClienteAnterior = clientesBox.getSelectedItem().toString().substring(0, clientesBox.getSelectedItem().toString().indexOf(" "));
            nroKioscoAnterior = Integer.parseInt(kioscosBox.getSelectedItem().toString().substring(0, kioscosBox.getSelectedItem().toString().indexOf(" ")));
            formaPagoAnt = Integer.parseInt(formaPagoBox.getSelectedItem().toString().substring(0, formaPagoBox.getSelectedItem().toString().indexOf(" ")));
            servicioAnt = Integer.parseInt(serviciosBox.getSelectedItem().toString().substring(0, serviciosBox.getSelectedItem().toString().indexOf(" ")));
        }
    }
    else {
        if((clientesBox.getSelectedItem().equals("RIF - Cliente")) || (kioscosBox.getSelectedItem().equals("Kiosco - Nombre")) 
            || ((posicionBox.getSelectedItem().equals("Seleccione una posicion"))) || (serviciosBox.getSelectedItem().equals("Seleccione un servicio")) 
            || (formaPagoBox.getSelectedItem().equals("Seleccione un tipo") || (fechaInicioC.getDate() == null)
            || (fechaFinC.getDate() == null))){

            JOptionPane.showMessageDialog(this, "Error, campos incompletos o erroneos");
        }
        else{
            try {   
                String rifCliente = clientesBox.getSelectedItem().toString().substring(0, clientesBox.getSelectedItem().toString().indexOf(" "));
                String fechaInicio = fecha.format(this.fechaInicioC.getDate());
                String fechaFin = fecha.format(this.fechaFinC.getDate());
                String posicion = posicionBox.getSelectedItem().toString();
                Integer nroFormaPago = Integer.parseInt(formaPagoBox.getSelectedItem().toString().substring(0, formaPagoBox.getSelectedItem().toString().indexOf(" ")));
                Integer nroServicio = Integer.parseInt(serviciosBox.getSelectedItem().toString().substring(0,serviciosBox.getSelectedItem().toString().indexOf(" ")));
                Integer nroKiosco = Integer.parseInt(kioscosBox.getSelectedItem().toString().substring(0,kioscosBox.getSelectedItem().toString().indexOf(" ")));
                Integer costoAlquiler = Integer.parseInt(montoField.getText());        
        
                int resultado = EdicionInformacion.editarAlquiler(nroAlquiler, fechaInicio, fechaFin, posicion, 
                        rifCliente, nroFormaPago, nroServicio, nroKiosco, costoAlquiler, 
                        porcentajeDescuentoTotal, rifClienteAnterior, nroKioscoAnterior, formaPagoAnt, servicioAnt);        
                
                if (resultado != 0){
                    JOptionPane.showMessageDialog(this, "Edición Exitosa");
                    limpiarCamposInfoAlquiler();
                    limpiarCamposCreacionAlquiler();
                    this.jTabbedPane1.setSelectedIndex(0);
                    this.mostrarInfoAlquiler(rifCliente);  
                    this.infoPubli_Text.setText("");
                    this.jTabbedPane1.setEnabledAt(1, false);
                    this.jTabbedPane1.setTitleAt(1, "");
                }
            } catch (SQLException ex) {
                System.out.println(ex);
            }
        }
    }
}//GEN-LAST:event_editarButtonActionPerformed

private void fechaInicioCPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_fechaInicioCPropertyChange
    if (this.fechaInicioC.getDate() != null)
        this.calcularFechasAlquiler(this.serviciosBox.getSelectedItem().toString().substring(0,1));
}//GEN-LAST:event_fechaInicioCPropertyChange

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backButton;
    private javax.swing.JComboBox clientesBox;
    private javax.swing.JPanel creacionAlq_Panel;
    private javax.swing.JButton editarButton;
    private javax.swing.JButton eliminarButton;
    private com.toedter.calendar.JDateChooser fechaFinC;
    private com.toedter.calendar.JDateChooser fechaInicioC;
    private javax.swing.JComboBox formaPagoBox;
    private javax.swing.JPanel infoAlq_Panel;
    private javax.swing.JComboBox infoBox;
    private javax.swing.JTable infoPubli_Table;
    private javax.swing.JTextArea infoPubli_Text;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JComboBox kioscosBox;
    private javax.swing.JTextField montoField;
    private javax.swing.JComboBox posicionBox;
    private javax.swing.JLabel posicionLabel;
    private javax.swing.JButton registrarButton;
    private javax.swing.JComboBox serviciosBox;
    // End of variables declaration//GEN-END:variables
}
